<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="css/style.css">
    <script src="js/jquery.min.js"></script>
    <script src="js/main.js"></script>
</head>
<body>
<div class="main">
    <div class="header">
        <div class="headerL">
            <img src="images/u7.png">
            <div class="name">
                <p class="name1">
                    山东大学附属儿童医院
                </p>
                <p class="des">
                    Childern’s Hospital Affiliated to Shandong Universitry
                </p>
            </div>
        </div>
        <div class="headerR">
            <span id="kyear"></span>
            <span id="ktime"></span>
        </div>
    </div>
    <div class="con">
        <div class="title">
            <a id="goIndex">返回首页</a>
            <span id="timeOut"></span>
        </div>
        <div class="chushi">
            <div class="jiqi">
                <img src="images/dh.gif">
            </div>
            <p class="tip">
                请将电子健康码放置到指定读取区域
            </p>
            <a class="chushitxt">
                <input placeholder="请点击此处出示健康码" type="text" id="inputs" value="">
            </a>
        </div>
    </div>
    <div class="window" style="display: none">
        <div class="success">
            <h2>
                错误提示
            </h2>
            <p>
                请输入有效信息查询！
            </p>
            <a id="windowClose">
                关闭
            </a>
        </div>
    </div>
    <div class="footer">
        <img src="images/u29.svg">
        0531-87964999
    </div>
</div>
<script>
    daojishi()
    var tips = false;
    setInterval(function () {
        if (!tips) {
            $("#inputs").focus();
        }
    }, 200)

    $('#inputs').bind('keypress', function (event) {
        if (event.keyCode == "13") {
            var qrCode = $('#inputs').val();
            if ((qrCode !== undefined && qrCode.length >= 101) || (qrCode !== undefined && (qrCode.length === 15 || qrCode.length === 18))) {
                if (localStorage.getItem("tag") === 'fapiao') {
                    $.ajax({
                        url: domain + "/web/api/machine/getUserQr",
                        type: "post",
                        dataType: "json",
                        data: {'qrCode': qrCode, 'type': 'fapiao'},
                        success: function (data, textStatus, jqxhr) {
                            console.log("__成功__");
                            console.log(textStatus);
                            console.log(jqxhr);
                            console.log("______");
                            if (data.result && data.result.uwiList) {
                                console.log(data.result.uwiList);
                                localStorage.setItem("username", data.result.name)
                                localStorage.setItem("useridcard", data.result.idcard)
                                localStorage.setItem("idcardOld", data.result.idcardOld)
                                localStorage.setItem("fapiaoData", JSON.stringify(data.result.uwiList))
                            }else{
                                localStorage.setItem("username", undefined)
                                localStorage.setItem("useridcard",undefined)
                                localStorage.setItem("idcardOld", undefined)
                                localStorage.setItem("fapiaoData", undefined)
                                // $(".window").show();
                            }
                            if(data.code=='0000'){
                                window.location.href = "fapiao.html"
                            }else{
                                $(".window").show();
                                setTimeout(function () {
                                    $(".window").hide();
                                    window.location.href = 'index.html';
                                }, 5000)
                            }
                        },
                        error: function (jqxhr, textStatus, error) {
                            alert('请求失败！')
                        }
                    })
                }
                if (localStorage.getItem("tag") === 'baogao') {
                    $.ajax({
                        url: domain + "/web/api/machine/getUserQr",
                        type: "post",
                        dataType: "json",
                        data: {'qrCode': qrCode, 'type': 'baogao'},
                        success: function (data, textStatus, jqxhr) {
                            console.log("__成功__");
                            console.log(textStatus);
                            console.log(jqxhr);
                            console.log("______");
                            if (data.result && data.result.uwiList) {
                                console.log(data.result.uwiList);
                                localStorage.setItem("username", data.result.name)
                                localStorage.setItem("useridcard", data.result.idcard)
                                localStorage.setItem("idcardOld", data.result.idcardOld)
                                localStorage.setItem("baogaoData", JSON.stringify(data.result.userWaterRecord))

                            }else{
                                localStorage.setItem("username", undefined)
                                localStorage.setItem("useridcard", undefined)
                                localStorage.setItem("idcardOld", undefined)
                                localStorage.setItem("baogaoData", undefined)
                                // $(".window").show();
                            }
                            if(data.code=='0000'){
                                window.location.href = "baogao.html"
                            }else{
                                $(".window").show();
                                setTimeout(function () {
                                    $(".window").hide();
                                    window.location.href = 'index.html';
                                }, 5000)
                            }

                        },
                        error: function (jqxhr, textStatus, error) {
                            alert('请求失败！')
                        }
                    })
                }
            } else {
                tips = true
                $(".window").show();
                setTimeout(function () {
                    $(".window").hide();
                    window.location.href = 'index.html';
                }, 5000)
                $('#inputs').val("")
            }
        }
    });
</script>
</body>
</html>
